package com.llsydn.animation;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.llsydn.hello.R;

/**
 * @author lilinshen
 * @title Drawable 动画
 * @description 请填写相关描述
 * @date 2018/10/9 17:09
 */
public class DAActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView iv_da_mm;
    private Button btn_da_start;
    private Button btn_da_stop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_da);

        iv_da_mm = findViewById(R.id.iv_da_mm);
        btn_da_start = findViewById(R.id.btn_da_start);
        btn_da_stop = findViewById(R.id.btn_da_stop);

        btn_da_start.setOnClickListener(this);
        btn_da_stop.setOnClickListener(this);
    }

    private AnimationDrawable animationDrawable;

    /**
     * 启动，停止动画
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        if (v == btn_da_start) {
            if (animationDrawable == null) {
                //动画图片处理
                animationDrawable = (AnimationDrawable) iv_da_mm.getBackground();
                //启动
                animationDrawable.start();
            }
        } else if (v == btn_da_stop) {
            if (animationDrawable != null) {
                //停止
                animationDrawable.stop();
                animationDrawable = null;
            }
        }
    }
}
